using TMPro.EditorUtilities;
using UnityEditor;
using UnityEngine;

namespace EchoFramework.Editor
{
    /// <summary>
    /// <see cref="EchoTMP_Text"/>的编辑器面板
    /// </summary>
    [CustomEditor(typeof(EchoTMP_Text))]
    public class EchoTMP_TextInspector : TMP_EditorPanelUI
    {
        /// <summary>
        /// 面板参数
        /// </summary>
        private SerializedProperty langKey;
        /// <summary>
        /// 自身EText
        /// </summary>
        private EchoTMP_Text selfTxt;
        
        protected override void OnEnable()
        {
            base.OnEnable();
            selfTxt = target as EchoTMP_Text;
            langKey = serializedObject.FindProperty("langKey");
        }

        protected override void DrawExtraSettings()
        {
            base.DrawExtraSettings();
            EditorGUILayout.PropertyField(langKey, new GUIContent("langKey"));
            string langkeyStr = langKey.stringValue; 
            if (GUILayout.Button("加载文本"))
            {
                if (langkeyStr.StartsWith("#"))
                {
                    selfTxt.text = Global.GetPackageLang(langkeyStr);
                }
                else
                {
                    selfTxt.text = Global.GetLang(langkeyStr);
                }
            }
        }
    }
}